home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / systems / mac / euro-oztex / EOT2.1#2.sea.bin / PS-files / DVItoPS.ps < prev    next >
Text File  |  1993-07-10  |  13KB  |  424 lines

  1. %!
  2. % This is the prolog used by OzTeX 1.6 to convert a DVI file into PostScript.
  3.  
  4. % Set dev to "LW" if LaserWriter, "LINO" if Linotronic, or "?" if unknown:
  5.  
  6. /dev (?) def
  7. statusdict /product known {
  8.     statusdict /product get
  9.     (LaserWriter) anchorsearch { pop pop /dev (LW) def } { pop } ifelse
  10.     statusdict /product get
  11.     (Linotype) anchorsearch { pop pop /dev (LINO) def } { pop } ifelse
  12. } if
  13.  
  14. /@setup {                            % set up OzTeX's coordinate system
  15.  
  16. /res  exch def                        % desired resolution (defines dots per inch)
  17. /voff exch def                        % vertical offset (in dots)
  18. /hoff exch def                        % horizontal offset (in dots)
  19. /ht exch def                        % paper height (in dots)
  20. /wd exch def                        % paper width (in dots)
  21.  
  22. /land wd ht gt def                % print in landscape orientation?
  23. /oshift ht res sub neg def        % vertical shift (in dots) for portrait origin
  24.  
  25. dev (?) eq                                        % unknown device?
  26. { land
  27.     {                                                % landscape
  28.         90 rotate                                % rotate axes 90deg anticlockwise
  29.         72 res div dup neg scale            % units now device dots
  30.         res dup translate                        % move to TeX origin
  31.         voff neg hoff translate                % adjust TeX origin if necessary
  32.     }
  33.     {                                                % portrait
  34.         72 res div dup neg scale            % units now device dots
  35.         res oshift translate                    % move to TeX origin
  36.         hoff voff translate                    % adjust TeX origin if necessary
  37.     } ifelse
  38. } if
  39.  
  40. dev (LW) eq                                        % LaserWriter?
  41. {
  42.     % Display model and version in OzTeX window:
  43.     % (\rmodel = ) print statusdict /product get print
  44.     % (\rversion = ) print version print (\r) print flush
  45.  
  46.    land
  47.     {                                                % landscape
  48.         90 rotate                                % rotate axes 90deg anticlockwise
  49.         72 res div dup neg scale            % units now device dots
  50.         res dup translate                        % move to TeX origin
  51.         voff neg hoff translate                % adjust TeX origin if necessary
  52.         
  53.         % Model-specific adjustments to origin can be made here:
  54.         statusdict /product get (LaserWriter) eq
  55.         { -90 0 translate                                                % move left a bit
  56.         }
  57.         { statusdict /product get (LaserWriter Plus) eq
  58.         { -32 0 translate                                                % move left a bit
  59.         }
  60.         { statusdict /product get (LaserWriter II NTX) eq
  61.         { -20 0 translate                                                % move left a bit
  62.         }
  63.         { statusdict /product get (LaserWriter IIg) eq
  64.         { 0 0 translate
  65.         }
  66.         { % some other model
  67.           0 0 translate
  68.         }
  69.         ifelse } ifelse } ifelse } ifelse
  70.     }
  71.     {                                                % portrait
  72.         72 res div dup neg scale            % units now device dots
  73.         res oshift translate                    % move to TeX origin
  74.         hoff voff translate                    % adjust TeX origin if necessary
  75.         
  76.         % Model-specific adjustments to origin can be made here:
  77.         statusdict /product get (LaserWriter) eq
  78.         { 0 22 translate                                                % move down a bit
  79.         }
  80.         { statusdict /product get (LaserWriter Plus) eq
  81.         { 0 0 translate
  82.         }
  83.         { statusdict /product get (LaserWriter II NTX) eq
  84.         { 0 14 translate                                                % move down a bit
  85.         }
  86.         { statusdict /product get (LaserWriter IIg) eq
  87.         { 0 0 translate
  88.         }
  89.         { % some other model
  90.           0 0 translate
  91.         }
  92.         ifelse } ifelse } ifelse } ifelse
  93.     } ifelse
  94.     
  95.     % The matrix produced above can cause scaling problems,
  96.     % so round each matrix value to nearest integer and use setmatrix:
  97.     matrix currentmatrix
  98.     dup dup 0 get round cvi 0 exch put
  99.     dup dup 1 get round cvi 1 exch put
  100.     dup dup 2 get round cvi 2 exch put
  101.     dup dup 3 get round cvi 3 exch put
  102.     dup dup 4 get round cvi 4 exch put
  103.     dup dup 5 get round cvi 5 exch put
  104.     setmatrix
  105.     
  106.     % Display new matrix in OzTeX window:
  107.     % matrix currentmatrix
  108.     % dup 0 get (            ) cvs print ( ) print
  109.     % dup 1 get (            ) cvs print ( ) print
  110.     % dup 2 get (            ) cvs print ( ) print
  111.     % dup 3 get (            ) cvs print ( ) print
  112.     % dup 4 get (            ) cvs print ( ) print
  113.     % dup 5 get (            ) cvs print (\r) print flush
  114.     % pop
  115. } if
  116.  
  117. dev (LINO) eq                                    % Linotronic?
  118. { land
  119.   {                                                % landscape
  120.      90 rotate                                    % rotate axes 90deg anticlockwise
  121.      72 res div dup neg scale                % units now device dots
  122.      res dup translate                        % move to TeX origin
  123.      voff neg hoff translate                % adjust TeX origin if necessary
  124.   }
  125.   {                                                % portrait
  126.      newpath clippath pathbbox                % push LLx LLy URx URy (URy = ht in pts)
  127.      /paperht exch 72 div def                % paper height in inches
  128.      pop pop pop                                % remove URx LLy LLx
  129.      72 res div dup neg scale                % units now device dots
  130.      res paperht res mul neg res add
  131.                                   translate        % move to TeX origin
  132.      hoff voff translate                        % adjust TeX origin if necessary
  133.   } ifelse
  134. } if
  135.  
  136. % Some fine-tuning of the code used to draw a rule is necessary.
  137. % Use page 18 in nasty.dvi to check results:
  138.  
  139. dev (LW) eq                                    % LaserWriter?
  140. { version cvr 38.0 le                    % early model?
  141.   { land
  142.     {                                            % landscape
  143.           /r                                    % set a wd by ht rule at h,v
  144.           { newpath
  145.              moveto                            % move to h,v
  146.              /ht exch 1 sub def            % reduce height by 1
  147.              /wd exch 1 sub def            % ditto for width
  148.              wd 0 rlineto
  149.              0 ht neg rlineto
  150.              wd neg 0 rlineto
  151.              fill
  152.           } bind def
  153.       }
  154.       {                                        % portrait
  155.           /r                                    % set a wd by ht rule at h,v
  156.           { newpath
  157.              1 add moveto                    % move to h,v+1
  158.              /ht exch 1 sub def            % reduce height by 1
  159.              /wd exch 1 sub def            % ditto for width
  160.              wd 0 rlineto
  161.              0 ht neg rlineto
  162.              wd neg 0 rlineto
  163.              fill
  164.           } bind def
  165.       } ifelse
  166.   } if
  167.   version cvr 2000.0 gt                    % IIg or newer model?
  168.   {
  169.       /r                                        % set a wd by ht rule at h,v
  170.       { newpath
  171.          1 add moveto                        % move to h,v+1
  172.          /ht exch def                        % set height
  173.          /wd exch def                        % set width
  174.          wd 0 rlineto
  175.          0 ht neg rlineto
  176.          wd neg 0 rlineto
  177.          fill
  178.       } bind def
  179.   } if
  180. } if
  181.  
  182. /mtrx 6 array def
  183. mtrx currentmatrix pop                    % save our new transformation matrix
  184.  
  185. } def                                            % end of @setup
  186.  
  187. % @saveVM and @restoreVM are only used if we are conserving VM
  188. % by downloading font bitmaps more often:
  189.  
  190. /@saveVM {/prefontVM save def} def
  191. /@restoreVM {prefontVM restore} def
  192.  
  193. /@newfont                                    % create new font dict
  194. { /maxchcode exch def
  195.   /fontid exch def
  196.   fontid 7 dict def
  197.   fontid load begin
  198.       /FontType 3 def
  199.       /FontMatrix [1 0 0 -1 0 0] def    % -1 because y scale is negative
  200.       /FontBBox [0 0 1 1] def
  201.       /BitMaps maxchcode 1 add array def
  202.       /BuildChar {CharBuilder} def
  203.  
  204.       /Encoding 256 array def
  205.       0 1 255 {Encoding exch /.notdef put} for
  206.  
  207.       % The above 2 lines fix a definefont error that occurs on some printers
  208.       % (eg. the LaserWriter NTX-J).  If you have an old LaserWriter and
  209.       % now get VM errors then you might want to revert to the old code:
  210.       %
  211.       % /Encoding maxchcode 1 add array def
  212.       % 0 1 maxchcode {Encoding exch /.notdef put} for
  213.  
  214.       end
  215.   fontid fontid load definefont pop
  216. } def
  217.  
  218. % The char data, a bitmap descriptor, is an array with 6 elements;
  219. % element 0 is either a hex string or an array of hex strings (the latter
  220. % is required for large PK chars with more than 65535 hex digits):
  221.  
  222. /ch-image    {ch-data 0 get dup type /stringtype ne {N get /N N 1 add def} if
  223.                 } def                            % hex string
  224. /ch-width    {ch-data 1 get} def        % the number of pixels across
  225. /ch-height    {ch-data 2 get} def        % the number of pixels tall
  226. /ch-xoff        {ch-data 3 get} def        % number of pixels to left of origin
  227. /ch-yoff        {ch-data 4 get} def        % number of pixels below origin
  228. /ch-advw        {ch-data 5 get} def        % advance width
  229.  
  230. % The following character builder looks up the char data in the BitMaps array
  231. % and paints the character:
  232.  
  233. /CharBuilder                                % image one char
  234. { /ch-code exch def                        % save the char code
  235.   /font-dict exch def                    % and the font dict
  236.   /ch-data font-dict /BitMaps get
  237.   ch-code get def
  238.   /N 0 def
  239.       ch-advw 0
  240.       ch-xoff neg ch-height ch-yoff sub 1 sub neg    % -xo , -(ht-yo-1)
  241.       ch-width ch-xoff sub 1 sub ch-yoff                % (wd-xo-1) , yo
  242.   setcachedevice
  243.       ch-width ch-height true
  244.       [1 0 0 -1 ch-xoff ch-yoff]        % bitmap sent top to bottom
  245.       {ch-image}
  246.   imagemask
  247. } def
  248.  
  249. /sf {setfont} def                            % set current font
  250.  
  251. /dc                                            % define new character
  252. { /ch-code exch def
  253.   /ch-data exch def
  254.  
  255.   % The following code should be enabled if you have an old LaserWriter.
  256.   % It attempts to overcome a bug that causes the printer to crash
  257.   % and print a test page rather then report a VMerror.
  258.   %
  259.   % vmstatus                                % returns: savelevel vmused vmmax
  260.   % 10000 sub gt                            % is vmused > (vmmax-10000)?
  261.   %    { pop VMERROR }                    % causes error message (avoiding crash)
  262.   %    { pop }                                % pop savelevel
  263.   % ifelse
  264.  
  265.   currentfont /BitMaps get ch-code ch-data put
  266.   currentfont /Encoding get ch-code
  267.   dup (   ) cvs cvn put                    % generate unique name
  268. } bind def
  269.  
  270. /@bop0 {pop} def                            % begin DVI page n
  271.  
  272. /@bop1                                        % begin setting DVI page n
  273. { pop                                            % throw away page number
  274.   initgraphics                                % start with a clean slate
  275.   mtrx setmatrix                            % switch to our TeX coordinate system
  276.   /prepageVM save def                    % save state of VM at start of page
  277. } def
  278.  
  279. /@eop                                            % end DVI page n
  280. { pop                                            % throw away page number
  281.   prepageVM restore                        % restore VM to state at start of page
  282.   showpage
  283. } def
  284.  
  285. /@end { } def                                % end of file
  286.  
  287. % h and s are used to typeset downloaded bitmap fonts:
  288.  
  289. /h {exch 0 rmoveto show} bind def    % move right by dh and show (...)
  290.  
  291. /s {3 1 roll moveto show} bind def    % move to h,v and show (...)
  292.  
  293. % H and S are used to typeset PostScript fonts.
  294. % We can't use relative horizontal positioning because the advance widths in
  295. % a PostScript font are not integers and rounding errors would accumulate:
  296.  
  297. /H {exch v moveto show} bind def        % move to h,v and show (...)
  298.  
  299. /S                                                % ditto, and save v position
  300. { 3 1 roll
  301.   1 add                                        % v+1 to match baseline of bitmap fonts
  302.   dup /v exch def
  303.   moveto show
  304. } bind def
  305.  
  306. % r is used to typeset a rule:
  307.  
  308. /r                                                % set a wd by ht rule at h,v
  309. { newpath
  310.   moveto                                        % move to h,v
  311.   /ht exch 1 sub def                        % reduce height by 1
  312.   /wd exch 1 sub def                        % ditto for width
  313.   wd 0 rlineto
  314.   0 ht neg rlineto
  315.   wd neg 0 rlineto
  316.   fill
  317. } bind def
  318.  
  319. % Following procedures are invoked as the result of \special{file}.
  320. % We change all scaling and graphics back to defaults, but shift the origin
  321. % to the current position on the page:
  322.  
  323. /@bsp
  324. { /vmag exch def                            % vertical scaling
  325.   /hmag exch def                            % horizontal scaling
  326.   moveto                                        % move to h,v
  327.   gsave
  328.   /prespecialVM save def                % save showpage, TeX procedures etc.
  329.   currentpoint transform
  330.   initgraphics itransform translate
  331.   hmag vmag scale
  332.   land { 90 rotate } if                    % rotate axes if landscape
  333.   /showpage { } def                        % user does not have to remove showpage
  334. } bind def
  335.  
  336. /@esp
  337. { prespecialVM restore                    % restore saved showpage value etc.
  338.   grestore
  339. } bind def
  340.  
  341. % Following procedures are invoked as the result of \special{epsf=file}.
  342. % Note that @bepsf and @eepsf are currently identical to @bsp and @esp
  343. % but it is a good idea to allow for future changes:
  344.  
  345. /@bepsf
  346. { /vmag exch def                            % vertical scaling
  347.   /hmag exch def                            % horizontal scaling
  348.   moveto                                        % move to h,v
  349.   gsave
  350.   /prespecialVM save def                % save showpage, TeX procedures etc.
  351.   currentpoint transform
  352.   initgraphics itransform translate
  353.   hmag vmag scale
  354.   land { 90 rotate } if                    % rotate axes if landscape
  355.   /showpage { } def                        % user does not have to remove showpage
  356. } bind def
  357.  
  358. /@eepsf
  359. { prespecialVM restore                    % restore saved showpage value etc.
  360.   grestore
  361. } bind def
  362.  
  363. % Here is the code to handle bitmaps generated by PICT/PNTG \specials:
  364.  
  365. /@bitmap
  366. { /vmag exch def                            % vertical scaling
  367.   /hmag exch def                            % horizontal scaling
  368.   /vres exch def                            % vertical resolution of bitmap
  369.   /hres exch def                            % horizontal resolution of bitmap
  370.   /ht exch def                                % height
  371.   /wd exch def                                % width
  372.   /hexstring ht string def
  373.   gsave
  374.      1 add translate                        % set origin to h,v+1
  375.      res hres div wd mul hmag mul
  376.      res vres div ht mul vmag mul neg scale
  377.      wd ht true
  378.      [ wd 0 0 ht neg 0 ht ]
  379.      { currentfile hexstring readhexstring pop }
  380.      imagemask
  381.   grestore
  382. } def
  383.  
  384. % Here are the definitions needed to handle PostScript fonts:
  385.  
  386. /sp                                            % scaled pts to device dots
  387. { 16#10000 div                                % scaled pts to pts
  388.   res mul 72.27 div                        % pts to device dots
  389. } bind def
  390.  
  391. /PSfont
  392. { /fontname exch def                        % printer font name
  393.   /dotsize exch def                        % scaled dot size
  394.   /done false def
  395.  
  396.   % check if fontname is one of the special printer font names
  397.   % appearing in the current config file's PS font list:
  398.   fontname /Slanted-Times-Roman eq
  399.   { /Times-Roman findfont [1 0 .167 -1 0 0] makefont
  400.     dotsize scalefont setfont
  401.     /done true def
  402.   } if
  403.  
  404.   % other nice tricks can be included here if the appropriate PS font
  405.   % specification is added to the current config file:
  406.   % fontname /Extended-Times-Roman eq
  407.   % { /Times-Roman findfont [1.2 0 0 -1 0 0] makefont
  408.   %   dotsize scalefont setfont
  409.   %   /done true def
  410.   % } if
  411.   
  412.   done not
  413.   { fontname findfont [1 0 0 -1 0 0] makefont
  414.     dotsize scalefont setfont
  415.   } if
  416. } bind def
  417.  
  418. % count 0 gt
  419. % { (\r *** Bug in DVItoPS.ps: stuff left on stack *** \r) print flush
  420. % } if
  421.  
  422. % --------------- end of OzTeX's prolog ---------------
  423.  
  424.